/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jocabulary;

import java.io.*;
import java.net.*;

/**
 *
 * @author pit
 */
public class FileDownloader {

    private String baseURL = "http://jocabulary.klysky.de/data/";
    private String baseFolder = "data/";

    public void downloadFile(String fileName) {
        try {
            URL file = new URL(baseURL+fileName);
            URLConnection fc = file.openConnection();
            fc.setConnectTimeout(5000);
            
            BufferedReader in = new BufferedReader( new InputStreamReader( fc.getInputStream() ) );

            FileWriter fstream = new FileWriter(baseFolder+fileName);
            BufferedWriter out = new BufferedWriter(fstream);

            for(String inputLine; (inputLine = in.readLine()) != null;) {
               out.write(inputLine+"\n");
            }

            out.close();
            in.close();
        } catch(IOException e) { System.out.println("Was not able to download file. Exception :"+e); }
    }

    public void fileExists(String fileName) throws IOException {
        URL file = new URL(baseURL+fileName);
        URLConnection fc = file.openConnection();
    }

}
